package com.tanhua.manage.controller;

import com.tanhua.manage.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/manage")
public class UserController {

    @Autowired
    private UserService userService;


    /**
     * 接口名称：用户数据翻页
     * 接口路径：GET/manage/users
     */
    @GetMapping("users")
    public ResponseEntity<Object> findByPage(Integer page, Integer pagesize) {
        return userService.findByPage(page, pagesize);
    }

    /**
     * 接口名称：用户基本资料
     * 接口路径：GET/manage/users/:userID
     */
    @GetMapping("users/{userID}")
    public ResponseEntity<Object> findUserInfoById(@PathVariable Long userID) {
        return userService.findUserInfoById(userID);
    }

    /**
     * 接口名称：动态分页
     * 接口路径：GET/manage/messages
     */
    @GetMapping("messages")
    public ResponseEntity<Object> queryPublishList(Integer page, Integer pagesize, String uid, String state) {
        //前端有可能传过来的state参数是"''"，这里做个统一过滤都改为null（要先做个非空判断，防止空指针异常）
        if (state != null) {
            if (state.equals("") || state.equals("''")) {
                state = null;
            }
        }
        //前端传过来的一直是10，这里改为12
        pagesize = 12;
        return userService.queryPublishList(page, pagesize, uid, state);
    }

    /**
     * 接口名称：视频记录翻页
     * 接口路径：GET/manage/videos
     */
    @GetMapping("videos")
    public ResponseEntity<Object> queryVideoList(Integer page, Integer pagesize, Long uid) {
        return userService.queryVideoList(page, pagesize, uid);
    }

    /**
     * 接口名称：动态详情
     * 接口路径：GET/manage/messages/:id
     */
    @GetMapping("messages/{id}")
    public ResponseEntity<Object> findById(@PathVariable String id) {
        return userService.findById(id);
    }

    /**
     * 接口名称：评论列表翻页
     * 接口路径：GET/manage/messages/comments
     */
    @GetMapping("messages/comments")
    public ResponseEntity<Object> queryCommentList(Integer page, Integer pagesize, String messageID) {
        return userService.queryCommentList(page, pagesize, messageID);
    }

    /**
     * 接口名称：动态拒绝
     * 接口路径：POST/manage/messages/reject
     */
    @PostMapping("/messages/reject")
    public ResponseEntity<Object> PublishReject(@RequestBody List<String> publishIdList) {
        return userService.PublishReject(publishIdList);
    }

    /**
     * 接口名称：动态通过
     * 接口路径：POST/manage/messages/pass
     */
    @PostMapping("/messages/pass")
    public ResponseEntity<Object> PublishPass(@RequestBody List<String> publishIdList) {
        return userService.PublishPass(publishIdList);
    }

    /**
     * 接口名称：用户冻结操作
     * 接口路径：POST/manage/users/freeze
     */
    @PostMapping("/users/freeze")
    public ResponseEntity<Object> userFreeze(@RequestBody Map<String, Object> param) {
        log.info("接口名称：用户冻结操作");
        return userService.userFreeze(param);
    }

    /**
     * 接口名称：用户解冻操作
     * 接口路径：POST/manage/users/unfreeze
     */
    @PostMapping("/users/unfreeze")
    public ResponseEntity<Object> unFreeze(@RequestBody Map<String, Object> param) {
        log.info("接口名称：用户解冻操作");
        return userService.unFreeze(param);
    }
}
